package com.lostad.app.vert.websocket;

import com.lostad.app.vert.util.Runner;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;

/*
 * @author <a href="http://tfox.org">Tim Fox</a>
 */
public class Client extends AbstractVerticle {

  // Convenience method so you can run it in your IDE
  public static void main(String[] args) {
    Runner.runExample(Client.class);
  }

  @Override
  public void start() throws Exception {
    HttpClient client = vertx.createHttpClient();

    client.websocket(9999, "localhost", "/chat/room1", websocket -> {
      websocket.handler(data -> {
        System.out.println("<<<<<<<<<<Received:" + data.toString());
        //client.close();
      });
      
      String msg = ">>>>>>>hello Server!";
      System.out.println(msg);
      websocket.writeBinaryMessage(Buffer.buffer(msg));
      
      msg = ">>>>>>>fuck server!";
      System.out.println(msg);
      websocket.writeFinalTextFrame(msg);
    });
  }
}
